package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.TeacherDao;
import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao teadao = new TeacherDao();

    //添加功能
    public boolean addTeacehr(Teacher tea) {
        return teadao.addTeacher(tea);
    }

    //删除功能
    public boolean deleteTeacher(String id) {
        return teadao.deleteTeacher(id);


    }

    //修改功能
    public void updateTeacher(String updateId, Teacher tea) {
        teadao.updateTeacher(updateId, tea);

    }

    //查看功能
    public Teacher[] findAllTeacher() {
        Teacher[] teas = teadao.findAllTeacher();
        //标记位判断系统容器是否为空,假设系统中没有有效数据
        boolean flag = false;
        for (int i = 0; i < teas.length; i++) {
            if (teas[i] != null) {
                flag = true;
            }
        }
        if (!flag) {
            return null;
        } else {
            return teas;
        }
    }

    //判断工号是否存在的方法
    public boolean isExists(String id) {
        return teadao.getIndex(id) != -1;
    }
}

